
import aufgabe3.*;



/**
 * @author Johannes Riedmann
 * @author David Medenjak
 * @author Lukas K�ll
 */
public class Test {

    /**
     * Main class, program start.
     * Tests our class structures :)
     * @param args not used
     */
    public static void main(String[] args) {
        String hr = "-------------------------------------";

        System.out.println("Every Object in this Application is a subtype of Polygon.");
        System.out.println("So the first step is to create (for example) a Rectangle-Object.\n");

        //casting Rectangle to Polygon
        Rectangle rec = new Rectangle(10, 10);

        System.out.println("Now we cast the Rectangle-Object into a Polygon.");

        Polygon p = (Polygon) rec;

        getProperties(p);

        System.out.println("We successfully casted the Rectangle-Object into a Polygon"
                + ", so Rectangle has to be subtype of Polygon.");

        System.out.println(hr + "\n");

        System.out.println("Now we try the same cast with a Triangle-Object.");

        //casting Triangle to Polygon
        Triangle tri = new Triangle(10, 5, 2);

        p = (Polygon) tri;

        getProperties(p);

        System.out.println("We successfully casted the Triangle-Object into a Polygon"
                + ", so Triangle has to be subtype of Polygon.\n");

        System.out.println(hr + "\n");

        //casting Rectangle into Triangle doesn't work
        //tri = (Triangle)rec;

        System.out.println("Now let's see if Square and EquilateralTriangle are subtypes "
                + "of Regularpolynom.");
        Square squ = new Square(10);
        EquilateralTriangle etri = new EquilateralTriangle(10);

        //squ.set(10); Unnecessary: Added in constructor
        //etri.set(10);

        RegularPolygon rpo = (RegularPolygon) squ;
        getProperties(rpo);

        rpo = (RegularPolygon) etri;
        getProperties(rpo);

        System.out.println("Casting Square- and EquilateralTriangle-Object to "
                + "RegularPolygon worked.\n");

        //casting Triangle- or Rectangle-Object to RegularPolygons won't work
        //rpo = (RegularPolygon)tri;
        //rpo = (RegularPolygon)rec;

        System.out.println("Let's see if every RegularPolygon/Rectangle is a ScalablePolygon.\n");

        ScaleablePolygon spo = (ScaleablePolygon) rec;
        getProperties(spo);

        System.out.println("Rectangle successfully casted into a ScalablePolygon.");

        spo = (ScaleablePolygon) rpo;
        getProperties(spo);

        System.out.println("RegularPolygon successfully casted into a ScalablePolygon.");

        /*  casting a Triangle into ScalablePolygon doesn't work, because
        Triangle is no subtype of ScalablePolygon */

        try {
            spo = (ScaleablePolygon) tri;
        } catch (Exception e) {
            System.out.println(e);
        }

        System.out.println(hr + "\n");


    }

    /**
     * Prints our debug output
     * @param p Polygon to get data of.
     */
    private static void getProperties(Polygon p) {
        System.out.println("\nCurrent type: " + p.getClass().getSimpleName() + ","
                + "\nNumber of edges: " + p.edges() + ","
                + " Area: " + p.area()
                + " and Perimeter: " + p.perimeter() + "\n");
    }
}
